package top.buyibuyi.course.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.listener.ReadListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import top.buyibuyi.course.dao.UploadFileDao;
import top.buyibuyi.course.esayExcel.ExcelListener;
import top.buyibuyi.course.esayExcel.ExcelStuSchose;
import top.buyibuyi.course.listener.StuExcelListener;
import top.buyibuyi.course.pojo.StuSchose;
import top.buyibuyi.course.service.UploadFileService;

import java.io.InputStream;
import java.util.Map;

@Service
public class UploadFileServiceImpl implements UploadFileService {

    @Autowired
    private UploadFileDao uploadFileDao;


    @Override
    public Boolean uploadExcel(MultipartFile file,UploadFileService uploadFileService) {
        try {
            InputStream inputStream = file.getInputStream();

            EasyExcel.read(inputStream,ExcelStuSchose.class,new StuExcelListener(uploadFileService)).sheet().doRead();

            return true;
        }catch (Exception e){
            e.printStackTrace();

            return false;
        }
    }

    @Override
    public Boolean save(StuSchose chose) {
        return uploadFileDao.save(chose);
    }
}
